package com.example.mybatisplus.service.impl;

import bigmodel.BigModelNew;
import com.example.mybatisplus.model.domain.Movie;
import com.example.mybatisplus.mapper.MovieMapper;
import com.example.mybatisplus.service.MovieService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fmx
 * @since 2024-11-17
 */
@Service
public class MovieServiceImpl extends ServiceImpl<MovieMapper, Movie> implements MovieService {
    @Autowired
    private MovieService movieService;
    @Autowired
    private MovieMapper movieMapper;
    @Override
    public List<Movie> getMoviesByIds(List<Integer> movieIds) {
        List<Movie> movies = new ArrayList<>();
        for (Integer movieId : movieIds) {
            Movie movie = movieService.getById(movieId);
            if (movie != null) {
                movies.add(movie);
            }
        }
        return movies;
    }

    @Override
    public Movie addmovie(Movie movie) {
        if(movieService.ifMovieExist(movie.getMovieName())){
            // 电影已存在
            return movieMapper.selectByMovieName(movie.getMovieName());
        }

        //已修改
        movieMapper.insert(movie);
        return movie;
    }

    @Override
    public boolean ifMovieExist(String movieName) {
        return movieMapper.existsByName(movieName);
    }
    public Movie selectByName(String movieName) {return movieMapper.selectByMovieName(movieName);}

    public String getSingleAnswer(BigModelNew bigModelNew){
        return bigModelNew.singleAnswer;
    }


}
